<script>
	import {
		getUserInfo,
		setLogin,
		setUserOpenid
	} from "@/utils/storage.js"
	import {
		setToken,
		getToken
	} from '@/utils/token.js'
	import {
		selectUserByTerminalModel
	} from '@/common/api/user.js'
	import {
		mapGetters
	} from 'vuex';
	export default {
		computed: {
			...mapGetters(['isLogin'])
		},
		onLaunch: function(option) {
			// #ifdef H5
			console.log('option.query', JSON.stringify(option.query));
			if(option.query.openId){
				setToken('deviceId', option.query.openId);
				setToken('version', option.query.version);
				setToken('modleName', option.query.modleName);
				console.log('this.isLogin2', this.isLogin);
				if (!this.isLogin) {
					selectUserByTerminalModel({
						terminalModel: getToken("deviceId")
					}).then(res => {
						let data = res && res.data
						console.log('data', data);
						console.log('data.code', data.code);
						if (data && data.code === 1) {
							//console.log('option.query.version', option.query.version);
							setLogin(res.data);
							if(option.query.version == 2){
								if(getToken('userInfo')['companyNo'] == getToken('complogin')['companyId']){
									setToken('version',2)
									setToken('useNum',getToken('complogin')['companyId'])
								}else{
									uni.navigateTo({
										url: `/pages/meSub/selectID?notPer=1&useNum=${getToken('userInfo')['craftsmanId']}`
									})
								}
							}
						}
					});
				} else {
							//console.log('已登录 option.query.version', option.query.version);
					if(option.query.version == 2){
						if(getToken('userInfo')['companyNo'] == getToken('complogin')['companyId']){
							setToken('version',2)
							setToken('useNum',getToken('complogin')['companyId'])
						}else{
							uni.navigateTo({
								url: `/pages/meSub/selectID?notPer=1&useNum=${getToken('userInfo')['craftsmanId']}`
							})
						}
					}
				}
			}
			// console.log('结束执行getWxCode', option.query.sendObj);
			 
			// #endif
			if(option.query.version == 1 && option.query.assoId== 'null' && option.query.windowUrl== 'null'){
				if(getToken('userInfo') &&　getToken('userInfo')['craftsmanId']){
					setToken('version',1)
					setToken('useNum',getToken('userInfo')['craftsmanId'])
				}
			} else if(option.query.version == 2 && option.query.assoId== 'null' && option.query.windowUrl== 'null'){
				if(getToken('userInfo')['companyNo'] == getToken('complogin')['companyId']){
					setToken('version',2)
					setToken('useNum',getToken('complogin')['companyId'])
				}else{
					uni.navigateTo({
						url: `/pages/meSub/selectID?notPer=1&useNum=${getToken('useNum')}`
					})
				}
			}
			if (option.query.windowUrl) {
				if (option.query.windowUrl == 'null') {
					setToken('windowUrl', '')
				} else {
					const windowUrl = JSON.parse(decodeURIComponent(option.query.windowUrl))
					setToken('windowUrl', windowUrl)
				}
			}
			if (option.query.assoId) {
				if (option.query.assoId == 'null') {
					setToken('assoId', '')
				} else {
					setToken('assoId', option.query.assoId)
				}
			}
			if (option.query.openId) {
				setUserOpenid(option.query.openId);
			}
			if (option.query.isLoad) {
				setToken('isLoad', option.query.isLoad)
			} else {
				setToken('isLoad', '')
			}
			
			if(option.query.sendObj){
				// console.log(JSON.parse(option.query.sendObj).useNum);
				// setToken('version', JSON.parse(option.query.sendObj).version)
				// setToken('useNum', JSON.parse(option.query.sendObj).useNum)
			}
			
			uni.onTabBarMidButtonTap(() => {
				if (!getToken('isLogin')) {
					this.$store.dispatch('toLoginWx', {
						showModal: true
					})
					return;
				}
			})
		},
		onShow: function() {
			// if(getToken('AUTH_TYPE'))
			// 	store.state.user.authType = getToken('AUTH_TYPE');
			console.log('App Show', getToken('AUTH_TYPE'))
			console.log('App Show')
		},
		onHide: function() {
			//console.log('App Hide')
		}
	}
</script>
<style lang="scss">
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "uview-ui/index.scss";
	.uni-btn-icon{
		color: #000!important;
	}
	.u-index-list__letter__item__index{
		font-size: 32rpx !important;
	}
	.u-index-list__letter__item{
		margin-bottom: 10rpx !important;
	}

	//按钮
	.btn-box-caozuo {
		background-color: #FFFFFF;
		padding: 12rpx 22rpx 20rpx 22rpx;
		width: 750rpx;
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 99;
	
		.btn-item {
			font-size: 30rpx;
			line-height: 82rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			margin: 0;
			padding: 0;
			flex: 1;
			margin: 0 10rpx;
			border-radius: 42rpx;
		}
	}
	.one-line{
		text-overflow: ellipsis;
		overflow: hidden;
		white-space: nowrap;
		width: 100%;
	}
</style>
